package mf.com.controller.sys;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import mf.com.Service.sys.SysRoleService;
import mf.com.dto.system.SysRoleDto;
import mf.com.entity.system.SysRole;
import mf.com.vo.common.Result;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: lmf
 * @Create: 2024/3/27 20:51
 * Description:  角色相关控制层
 */
@RestController
@RequestMapping("/admin/system/sysRole")
@Tag(name = "角色相关")
public class SysRoleController {
    @Resource
    private SysRoleService roleService;


    @PostMapping("/findByPage/{current}/{limit}")
    @Operation(summary = "角色分页查询")
    public Result<PageInfo<SysRole>> findByPage(@PathVariable("current") Integer current,
                                      @PathVariable("limit") Integer limit, @RequestBody SysRoleDto sysRoleDto){
        final PageInfo<SysRole> byPage = roleService.findByPage(sysRoleDto, current, limit);
        return Result.success(byPage);
    }


    @PostMapping("saveSysRole")
    @Operation(summary = "新增角色")
    public Result<SysRole> saveSysRole(@RequestBody SysRole sysRole){
        return Result.success(roleService.saveSysRole(sysRole));
    }


    @PutMapping("updateSysRole")
    @Operation(summary = "修改角色")
    public Result<SysRole> updateSysRole(@RequestBody SysRole sysRole){
        return Result.success(roleService.updateSysRole(sysRole));
    }

    @DeleteMapping("/deleteById/{roleId}")
    @Operation(summary = "删除角色")
    public Result<Integer> deleteById(@PathVariable("roleId") Integer roleId){
        return Result.success(roleService.deleteSysRole(roleId));
    }

    @GetMapping("/findAllRoles/{userId}")
    @Operation(summary = "查询用户角色")
    public Result<Map<String,Object>> findAllRoles(@PathVariable("userId") Integer userId){
        System.out.println(userId);
        final Map<String,Object> list = roleService.selectAll(userId);
        System.out.println(list);
        return Result.success(list);
    }

}
